#include "s_ipus_64Mb_user.h"
#include "s_ipus_64Mb.h"
#include "h_stm32_hal_spi.h"

#include <stdio.h>
#include <string.h>

#include "h_stm32_hal_timer.h"

static s_ipus_64Mb_t ipus_t;

void s_ipus_64Mb_user_init(void)
{
    ipus_t.spi_cs_enable = &h_stm32_hal_spi1_cs_enable;
    ipus_t.spi_cs_disable = &h_stm32_hal_spi1_cs_disable;
    ipus_t.spi_write = &h_stm32_hal_spi1_write;
    ipus_t.spi_read = &h_stm32_hal_spi1_read;
    ipus_t.delay_us = &delay_us;
} 

void s_ipus_64Mb_user_reset(void)
{
    s_ipus_64Mb_reset(&ipus_t);
}

void s_ipus_64Mb_user_test(void)
{

    signed char rslt = 0;
    unsigned char data[20], i;
    memset(data, 0x00, sizeof(data));

    s_ipus_64Mb_user_reset();

    // while(1);

    // s_nor_flash_user_erase_page(0x00);
    s_ipus_64Mb_read(&ipus_t, 0x00, data, sizeof(data));
    for(i = 0; i < sizeof(data); i++)
    {
        printf("0x%02x, ", data[i]);
    }
    printf("\r\n");

    for(i = 0; i < sizeof(data); i++)
    {
        data[i] = i + 1;
    }
    s_ipus_64Mb_write(&ipus_t, 0x00, data, sizeof(data));

    memset(data, 0x00, sizeof(data));
    s_ipus_64Mb_read(&ipus_t, 0x00, data, sizeof(data));
    for(i = 0; i < sizeof(data); i++)
    {
        printf("0x%02x, ", data[i]);
    }
    printf("\r\n");

    
    // rslt = s_nor_flash_user_close();
    // printf("the close rst is %d\r\n", rslt);

    // s_ipus_64Mb_readID(&ipus_t, &id);

    // printf("%d\n", id);
}